import { Component, OnInit } from '@angular/core';

import { Logger } from 'src/app/utils/Logger';
import { Hero } from '../app/Hero'
import { HeroService } from '../app/HeroService'

@Component({
  selector: 'app-hero-list',
  templateUrl: './hero-list.component.html',
  styleUrls: ['./hero-list.component.less'],
  // 依赖注入，必须。
  providers: [HeroService, Logger],
})
export class HeroListComponent implements OnInit {
  heroes: Hero[] = []
  selectedHero: Hero | undefined

  constructor(private service: HeroService, private logger: Logger) { }

  ngOnInit() {
    this.heroes = this.service.getHeroes()
  }

  selectHero(hero: Hero) {
    this.logger.writeCount(3)
    this.selectedHero = hero
  }
}
